package org.xin.framework.config;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;
import java.util.Collection;

/**
 * @author Long
 * @version 1.0
 * @description:
 * @remarks:
 * @title PageHelper
 * @date 2021/3/14 17:42
 */
@Setter
@Getter
@AllArgsConstructor
@ApiModel(description = "分页数据")
public class PageHelper<T> implements Serializable {
    private static final long serialVersionUID = 1L;
    @ApiModelProperty(value = "页码")
    private Integer page;
    @ApiModelProperty(value = "页大小")
    private Integer limit;
    @ApiModelProperty(value = "总数")
    private Integer total;
    @ApiModelProperty(value = "总页数")
    private long totalPages;
    @ApiModelProperty(value = "数据")
    private Collection<T> content;

    public static <T> PageHelper<T> create(Integer page, Integer limit, long total, long totalPages, Collection<T> content){
        page = page <= 0 ? 1 : page;
        limit = limit <= 0 ? 1 : limit;
        return new PageHelper<T>(page, limit, (int) total, totalPages, content);
    }

    public static <T> PageHelper<T> create(){
        return null;
    }
}
